import tkinter as tk

class LoginSys:
    def __init__(self, root):
        self.root = root
        self.root.title("登录注册")
        self.root.geometry("400x400")
        self.login_page()

    def login_page(self):
        self.clear_window()
        label = tk.Label(self.root, text="用户登录", font=("黑体", 20))
        label.place(x=135, y=30)

        label_username = tk.Label(self.root, text="用户名：", font=("宋体", 15))
        label_username.place(x=50, y=100)
        entry_username = tk.Entry(self.root, font=("宋体", 15))
        entry_username.place(x=150, y=100)

        label_password = tk.Label(self.root, text="密码：", font=("宋体", 15))
        label_password.place(x=50, y=150)
        entry_password = tk.Entry(self.root, font=("宋体", 15))
        entry_password.place(x=150, y=150)

        def login():
            print(entry_username.get())
            print(entry_password.get())

        login_button = tk.Button(self.root, command=login, text="登录", font=("宋体", 15))
        login_button.place(x=150, y=200)
        register_button = tk.Button(self.root, command=self.register_page, text="去注册", font=("宋体", 15))
        register_button.place(x=230, y=200)


    def register_page(self):
        self.clear_window()
        label = tk.Label(self.root, text="用户注册", font=("黑体", 20))
        label.place(x=135, y=30)

        label_username = tk.Label(self.root, text="用户名：", font=("宋体", 15))
        label_username.place(x=50, y=100)
        entry_username = tk.Entry(self.root, font=("宋体", 15))
        entry_username.place(x=150, y=100)

        label_password = tk.Label(self.root, text="密码：", font=("宋体", 15))
        label_password.place(x=50, y=150)
        entry_password = tk.Entry(self.root, font=("宋体", 15))
        entry_password.place(x=150, y=150)

        label_password = tk.Label(self.root, text="确认密码：", font=("宋体", 15))
        label_password.place(x=50, y=200)
        entry_password = tk.Entry(self.root, font=("宋体", 15))
        entry_password.place(x=150, y=200)

        def login():
            print(entry_username.get())
            print(entry_password.get())

        login_button = tk.Button(self.root, command=self.login_page, text="去登录", font=("宋体", 15))
        login_button.place(x=150, y=250)
        register_button = tk.Button(self.root, text="注册", font=("宋体", 15))
        register_button.place(x=230, y=250)

    def clear_window(self):
        """清除当前窗口所有组件"""
        for widget in self.root.winfo_children():
            widget.destroy()

if __name__ == '__main__':
    root = tk.Tk()
    app = LoginSys(root)
    root.mainloop()